using UnityEngine;
using System.Collections;

public class AnimationChar : MonoBehaviour {

	tk2dAnimatedSprite anim;
	CharacterMove person;
	bool walking = false;
	
	void Start () 
	{
        anim = GetComponent<tk2dAnimatedSprite>();
		person = GetComponent<CharacterMove>();
    }
	
	void HitCompleteDelegate(tk2dAnimatedSprite sprite, int clipId)
    {
        if (walking)
        {
            anim.Play("WalkTim");
        }
		else
		{
			anim.Stop();
		}
    }
	
	void Update () 
	{
        if (Input.GetAxis("Horizontal") != 0)
        {
			if(!anim.Playing && !person._AxisLeft.isGrounded && !person._AxisRight.isGrounded)
			{
            	anim.Play("WalkTim");
            	anim.animationCompleteDelegate = null;
            	walking = true;
			}
        }
		if (Input.GetAxis("Horizontal") == 0)
		{
            anim.Stop();
			anim.SetFrame(0);
            anim.animationCompleteDelegate = null;
            walking = false;
        }

	}
	
	

}
